package indiwood.model.service;

import indiwood.model.CinemaVO;
import indiwood.model.MovieVO;
import indiwood.model.ScheduleDateVO;
import indiwood.model.ScheduleTimeVO;
import indiwood.model.SeatVO;
import indiwood.model.ShowingVO;
import indiwood.model.TicketingVO;
import indiwood.model.dao.TicketingDAO;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

@Service
public class TicketingServiceImpl implements TicketingService {
	@Resource(name = "ticketingDAOImpl")
	private TicketingDAO ticketingDAO;
	@Override
	public HashMap<String, Object> orderListMap() {
		HashMap<String, Object> orderListMap= new HashMap<String, Object>();
		List<MovieVO> titleList= ticketingDAO.getAllShowingTitle();
		List<CinemaVO> cinemaList = ticketingDAO.getAllCinemaList();
		orderListMap.put("titleList", titleList);
		orderListMap.put("cinemaList", cinemaList);
		return orderListMap;
	}
	@Override
	public HashMap<String, Object> orderListMapByMovieNo(int movieNo) {
		HashMap<String, Object> orderListMap= new HashMap<String, Object>();
		List<CinemaVO> cinemaList = ticketingDAO.getAllCinemaListByNo(movieNo);
		MovieVO movieVO = ticketingDAO.getMovieContentByNo(movieNo);
		orderListMap.put("cinemaList", cinemaList);
		orderListMap.put("movieContent", movieVO);
		return orderListMap;
	}
	@Override
	public HashMap<String, Object> orderListMapByCinemaNo(ShowingVO showingVO) {
		HashMap<String, Object> orderListMap= new HashMap<String, Object>();
		List<MovieVO> titleList= ticketingDAO.getAllShowingTitleByNo(showingVO.getCinemaVO().getCinemaNo());
		orderListMap.put("titleList", titleList);
		ShowingVO getShowingVO = ticketingDAO.getAllShowingByNo(showingVO);
		orderListMap.put("showingVO", getShowingVO);
		return orderListMap;
	}
	@Override
	public List<ScheduleTimeVO> orderScheduleListByNo(ScheduleDateVO scheduleDateVO) {
		List<ScheduleTimeVO> scheduleList = ticketingDAO.getShowingScheduleTimeByNo(scheduleDateVO);
		return scheduleList;
	}
	@Override
	public ScheduleTimeVO getAllOrderByTicketingNo(TicketingVO ticketingVO) {
		ScheduleTimeVO allOrder = ticketingDAO.getAllOrderByTicketingNo(ticketingVO.getScheduleTimeVO().getTimeNo());
		return allOrder;
	}
	@Override
	public void writeTicketing(TicketingVO ticketingVO) {
		// ticketing insert
		ticketingDAO.writeTicketing(ticketingVO);
		// seat insert
		SeatVO seatVO = new SeatVO();
		ScheduleTimeVO sTimeVO = new ScheduleTimeVO();
		sTimeVO.setTimeNo(ticketingVO.getScheduleTimeVO().getTimeNo());
		seatVO.setScheduleTimeVO(sTimeVO);
		String result[] = ticketingVO.getSeat().split(",");
		for(int i=0;i<result.length;i++){
			seatVO.setInfo(result[i]);
			ticketingDAO.writeSeat(seatVO);
		}
	}
	@Override
	public List<TicketingVO> getTicketingListByEmail(String email) {
		List<TicketingVO> ticketingList = ticketingDAO.getTicketingListByEmail(email);
		return ticketingList;
	}
	@Override
	public List<SeatVO> getSeatInfoList(int timeNo) {
		List<SeatVO> seatInfoList = ticketingDAO.getSeatInfoList(timeNo);
		return seatInfoList;
	}
}
